scan_gridpanel_store = Ext.extend(Ext.data.Store, {
	constructor : function() {
		scan_gridpanel_store.superclass.constructor.call(this, {
					proxy : new Ext.data.HttpProxy({
								method : 'GET',
								url : 'cxxqysjsb/scan/getenterprisescan.action?uid='
										+ userId
							}),
					reader : new Ext.data.JsonReader({
								fields : ['attachment_id', 'enterprise_id',
										'attachment_name', 'attachment_type',
										'attachment_description',
										'attachment_create_time',
										'attachment_last_edit_time',
										'attachment_file_sources',
										'attachment_year',
										'attachment_type_sb',
										'attachment_is_new',
										'attachment_check_pass',
										'attachment_file_width',
										'attachment_file_heigth']
							}),
					autoLoad : true
				})
	}
});
scan_gridpanel = Ext.extend(Ext.grid.GridPanel, {
	store : null,
	addwin : null,
	constructor : function() {
		this.store = new scan_gridpanel_store();
		this.addwin = new uploadscanform_win();
		scan_gridpanel.superclass.constructor.call(this, {
			title : '已经上传的扫描材料',
			id : 'scan_gridpanel',
			region : 'north',
			iconCls : 'smledit',
			stripeRows : true,
			frame : false,
			height : 200,
			store : this.store,
			collapsible : true,
			sm : new Ext.grid.RowSelectionModel({
						singleSelect : true
					}),
			autoExpandColumn : 'attachment_name',
			columns : [new Ext.grid.RowNumberer(), {
						id : 'attachment_id',
						header : 'ID',
						width : 10,
						hidden : true,
						sortable : true,
						dataIndex : 'attachment_id'
					}, {
						id : 'enterprise_id',
						header : 'EID',
						width : 10,
						hidden : true,
						sortable : true,
						dataIndex : 'enterprise_id'
					}, {
						id : 'attachment_year',
						header : '年度',
						width : 100,
						hidden : false,
						sortable : true,
						align : 'center',
						renderer : this.getYearType,
						dataIndex : 'attachment_year'
					}, {
						id : 'attachment_type',
						header : '材料类型',
						width : 150,
						sortable : true,
						align : 'center',
						renderer : this.getAttachType,
						dataIndex : 'attachment_type'
					}, {
						id : 'attachment_name',
						header : '材料名称',
						width : 160,
						align : 'center',
						sortable : true,
						dataIndex : 'attachment_name'
					}, {
						id : 'attachment_description',
						header : '材料说明',
						width : 160,
						sortable : true,
						align : 'center',
						dataIndex : 'attachment_description'
					}, {
						id : 'attachment_create_time',
						header : '录入时间',
						width : 130,
						sortable : true,
						align : 'center',
						dataIndex : 'attachment_create_time'
					}, {
						id : 'attachment_last_edit_time',
						header : '最后编辑时间',
						width : 130,
						sortable : true,
						align : 'center',
						dataIndex : 'attachment_last_edit_time'
					}, {
						id : 'attachment_type_sb',
						header : '申报类型',
						width : 100,
						sortable : true,
						align : 'center',
						renderer : this.getattachment_type_sb,
						dataIndex : 'attachment_type_sb'
					}, {
						id : 'attachment_check_pass',
						header : '审核状态',
						width : 100,
						align : 'center',
						sortable : true,
						renderer : this.getattachment_check_pass,
						dataIndex : 'attachment_check_pass'
					}],
			tbar : [{
						text : '增加',
						iconCls : 'itemadd',
						scope : this,
						handler : function() {
							this.addwin.show(Ext.getDom('west-div'));
						}
					}, '-', {
						text : '删除',
						iconCls : 'delete',
						scope : this,
						handler : function() {
							var ro = this.getSelectionModel().getSelected();
							if (!ro) {
								Ext.Msg.show({
											title : '提示',
											msg : '你没有选择需要删除的数据',
											icon : Ext.Msg.ERROR,
											buttons : Ext.Msg.OK
										});
								return;
							}
							var benefit_check_pass = ro
									.get('attachment_check_pass');
							if (benefit_check_pass == '0') {
								Ext.Msg.show({
											title : '提示',
											msg : '正在审核的数据不能进行修改',
											icon : Ext.MessageBox.ERROR,
											buttons : Ext.Msg.OK
										});
								return;
							} else if (benefit_check_pass == 1
									|| benefit_check_pass == 2) {
								Ext.Msg.show({
											title : '提示',
											msg : '审核完成的数据不能进行修改',
											icon : Ext.MessageBox.ERROR,
											buttons : Ext.Msg.OK
										});
								return;
							} else {
								var attachment_id = ro.get('attachment_id');
								var enterprise_id = ro.get('enterprise_id');
								var attachment_name = ro.get('attachment_name');
								Ext.Msg
										.confirm('提示',
												'你确定要删除<font color="red">'
														+ attachment_name
														+ '</font>吗？',
												function(btn) {
													if (btn == 'yes') {
														Ext.Ajax.request({
															url : 'cxxqysjsb/scan/deleteEnterprise_AttachmentAction.action',
															scope : this,
															success : function(
																	response,
																	options) {
																if (response.responseText == 'ok') {
																	this
																			.fireEvent('refreshpic');
																	this
																			.getStore()
																			.reload();
																}
															},
															params : {
																id : attachment_id,
																eid : enterprise_id,
																name : attachment_name
															}
														});
													} else {
														return;
													}
												}, this);
							}
						}
					}, '-', {
						text : '刷新',
						iconCls : 'refreshtty',
						scope : this,
						handler : function() {
							this.fireEvent('refreshpic');
							this.getStore().reload();
						}
					}]
		});
		this.addEvents('refreshpic');
		this.addwin.on('uploadok',function(){this.fireEvent('refreshpic');
							this.getStore().reload();},this);
	},
	getYearType : function(value) {
		return value + '年';
	},
	getAttachType : function(code) {
		return getenterprsie_scan_combo_store(code);
	},
	getattachment_type_sb : function(code) {
		return '<font color="red">' + getDataType(code) + '</font>';
	},
	getattachment_check_pass : function(code) {
		return getCheckResultName(code);
	}

});
var interface_tpl = new Ext.XTemplate(
		'<tpl for=".">',
		'<div class="thumb-wrap" id="{attachment_name}">',
		'<div class="thumb"><img src="{attachment_file_sources}" title="{attachment_name}" width=150 height=150></img></div>',
		'<span class="x-editable">{shortName}</span></div>', '</tpl>',
		'<div class="x-clear"></div>');
scan_dataview = Ext.extend(Ext.DataView, {
			store : null,
			big_win : null,
			constructor : function() {
				this.store = new scan_gridpanel_store();
				scan_dataview.superclass.constructor.call(this, {
							id : 'images-view',
							style : 'overflow:auto',// 显示滚动条的做法
							store : this.store,
							tpl : interface_tpl,
							// height : 220,
							autoHeight : true,
							singleSelect : true,
							multiSelect : false,
							loadingText : '正在加载扫描材料简图',
							trackOver : true,
							itemSelector : 'div.thumb-wrap',
							overClass : 'x-view-over',
							// overClass : 'x-view-over',
							emptyText : '没有扫描简图信息',
							prepareData : function(data) { // 数据预处理,即数据处理前.data为原始数据,类型为对象.
								data.shortName = Ext.util.Format.ellipsis(
										data.attachment_name, 7); // 指定字符串为15个字符,超出部分用三个圆点代替.
								return data;
							}
						});
				this.on('dblclick', this.dblclick, this);
			},
			dblclick : function(dv, index, node, e) {
				if (this.big_win) {
					this.big_win.close();
				}
				var record = this.getStore().getAt(index);
				var imageurl = record.get('attachment_file_sources');
				var width = record.get('attachment_file_width');
				var height = record.get('attachment_file_heigth');
				var attachment_name = record.get('attachment_name');
				var _cfg = {
					url : imageurl,
					face_no : attachment_name,
					width : width,
					height : height
				};
				this.big_win = new scan_dataview_bigdraft_panel_win(_cfg);
				this.big_win.show();
				if (this.big_win) {
					// onmousewheel xia -10 shang 120
					// mousedown
					Ext.get(this.big_win.getEl()).on('mousewheel', function() {
								var delta = event.wheelDelta;
								this.big_win.change(delta);
							}, this);
					Ext.get(this.big_win.getEl()).on('mousedown', function(e) {
								if (e.button == 2) {
									this.menu = new closemenu();
									this.menu.showAt(e.getXY());
									this.menu.on('close', function() {
												this.big_win.hide();
											}, this);
									this.menu.on('big', function() {
												this.big_win.change(-1);
											}, this);
									this.menu.on('small', function() {
												this.big_win.change(1);
											}, this);
								}
							}, this);
				}
			},
			reload : function() {
				this.getStore().reload();
			}
		});
scan_dataview_panel = Ext.extend(Ext.Panel, {
			dataview : null,
			constructor : function() {
				this.dataview = new scan_dataview();
				scan_dataview_panel.superclass.constructor.call(this, {
							id : 'scan_dataview_panel',
							frame : true,
							pageX : 0,
							pageY : 0,
							autoHeight : true,
							region : 'center',
							// title : '扫描简图',
							iconCls : 'cad',
							tbar : [{
										text : '扫描简图',
										iconCls : 'star_sun',
										disabled : true
									}, '->', {
										text : '支持双击查看大图',
										iconCls : 'star_sun',
										disabled : true
									}],
							layout : 'fit',
							items : this.dataview
						});
			},
			reload : function() {
				this.dataview.reload();
			}

		});
all_panel = Ext.extend(Ext.Panel, {
			view : null,
			grid : null,
			constructor : function() {
				this.view = new scan_dataview_panel();
				this.grid = new scan_gridpanel();
				all_panel.superclass.constructor.call(this, {
							width : 900,
							iconCls : 'itemadd',
							height : 600,
							layout : 'border',
							defaults : {
								split : true
							},
							items : [this.view, this.grid]
						});
				this.grid.on('refreshpic', function() {
							this.view.reload();
						}, this);
			}
		});
uploadscanform = Ext.extend(Ext.form.FormPanel, {
	constructor : function() {
		uploadscanform.superclass.constructor.call(this, {
					baseCls : 'x-plain',
							method : 'post',
							autoHeight : true,
							autoWidth : true,
							modal : true,
							frame : true,
							fileUpload : true,
							bodyStyle : 'padding:0px 5px 0;',
							defaults : {
								width : 200,
								anchor : '90%'
							},
					items : [{
								xtype : 'hidden',
								name : 'uid',
								value : userId
							},{
								xtype : 'hidden',
								name : 'year',
								value : OPTION_NDDECLARE_YEAR
							},{
								xtype : 'hidden',
								name : 'type',
								value : OPTION_DATA_TYPE
							}, {
								xtype : 'textfield',
								name : 'attachment_name',
								fieldLabel : '材料名称'
							}, {
								xtype : 'combo',
								fieldLabel : '材料类型',
								store : enterprsie_scan_combo_store,
								mode : 'local',
								readOnly : true,
								allowBlank : false,
								triggerAction : 'all',
								displayField : 'name',
								valueField : 'id',
								editable : false,
								name : 'attachment_type'
							}, {xtype : 'fileuploadfield',
				id : 'uppartself',
				allowBlank : false,
				emptyText : '选择上传文件',
				fieldLabel : '上传图文档',
				name : 'imagefile',
				buttonCfg : {
					text : '',
					iconCls : 'star_sun'
				}}, {
								xtype : 'textfield',
								name : 'attachment_description',
								fieldLabel : '材料描述',
								allowBlank : true
							}]
				});
		this.addEvents('uploadok');
	},
	
	
	
//	new Ext.form.TextField({
//										// id : 'batchfile',
//										fieldLabel : '选择文件',
//										labelAlign : 'right',
//										name : 'imagefile',
//										inputType : 'file',
//										allowBlank : false,
//										blankText : '请选择文件！'
//									})
	submit : function() {

		if (this.getForm().isValid()) {
			this.getForm().submit({
						url : 'cxxqysjsb/scan/uploadEnterpriseAttachmentAction.action',// 没有添加
						method : 'post',
						scope : this,
						waitMsg : '文件正在上传,请稍后.......',
						success : function(_form, _action) {
							var msg = _action.result.msg;
							Ext.MessageBox.show({
										title : '文件上传',
										msg : msg,
										buttons : Ext.MessageBox.OK,
										icon : Ext.MessageBox.WARNING
									});
							this.fireEvent('uploadok');
						},
						failure : function(_form, _action) {
							var msg = _action.result.msg;
							Ext.Msg.show({
										title : '文件上传格式有误',
										msg : msg,
										buttons : Ext.MessageBox.OK,
										icon : Ext.MessageBox.ERROR
									});
						}
					})
		} else {
			Ext.Msg.show({
						title : '提示',
						msg : '请选择上传文件',
						icon : Ext.Msg.ERROR,
						buttons : Ext.Msg.OK
					});
			return;
		}
	}
});
uploadscanform_win = Ext.extend(Ext.Window, {
			myform : null,
			constructor : function() {
				this.myform = new uploadscanform();
				uploadscanform_win.superclass.constructor.call(this, {
							width : 400,
							title : '上传图文档',
							layout : 'fit',
							frame : true,
							iconCls : 'itemadd',
							closeAction : 'hide',
							plain : true,
							modal:true,
							items : this.myform,
							buttons : [{
										text : '保存',
										iconCls : 'itemadd',
										scope : this,
										handler : function() {
											this.myform.submit();
										}
									}, {
										text : '取消',
										iconCls : 'cancel',
										scope : this,
										handler : function() {
											this.myform.getForm().reset();
											this.hide();
										}
									}]
						});
				this.addEvents('uploadok');
				this.myform.on('uploadok',function(){this.fireEvent('uploadok');this.hide();},this);
			}
		});
Ext.extend(demo.module, {
			init : function() {
				this.all_panelbody = new all_panel();
				this.main.add(this.all_panelbody);
				this.main.doLayout();
			}
		});